/**   
 * @Title: MyQuestionActivity.java 
 * @Package com.jiuyang.baoxian.activity 
 * @Description: TODO(用一句话描述该文件做什么) 
 * @author ChangJianlong   
 * @date 2014-12-16 上午10:06:41 
 * @version V1.0   
 */
package com.bxd.baodan.activity;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.util.DisplayMetrics;
import android.util.TypedValue;

import com.bxd.baodan.App;
import com.bxd.baodan.R;
import com.bxd.baodan.fragment.BaseFragment;
import com.bxd.baodan.fragment.MyQuestionListFragment;
import com.bxd.baodan.widget.PagerSlidingTabStrip;
import com.umeng.analytics.MobclickAgent;

import java.util.ArrayList;
import java.util.List;

/**
 * @ClassName: MyQuestionActivity
 * @Description: TODO(这里用一句话描述这个类的作用)
 * @author ChangJianlong
 * @date 2014-12-16 上午10:06:41
 * 
 */
public class MyQuestionActivity extends BaseActivity {
	private ViewPager pager;
	private List<BaseFragment> fragmentList = new ArrayList<BaseFragment>();
	private MyFragmentPagerAdapter mAdapter;
	private PagerSlidingTabStrip tabs;
	private String[] strings = {"  提问  ","  评论  ","  赞过  "};
	private String[] params = {"","myComment","myLike"};



	@Override
	protected void onCreate(@Nullable Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_my_question);
		setActionBarTitle("我的问答");

		initView();

		initData();
	}

	private void initView() {
		pager = (ViewPager) findViewById(R.id.pager);
		tabs = (PagerSlidingTabStrip) findViewById(R.id.strip);
		mAdapter = new MyFragmentPagerAdapter(getSupportFragmentManager());
		pager.setAdapter(mAdapter);
		tabs.setViewPager(pager);

		pager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
			@Override
			public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

			}

			@Override
			public void onPageSelected(int position) {
				switch (position) {
					case 0:
						MobclickAgent.onEvent(App.getContext(), "v6_1_3_WD_wdwd_tw");
						break;
					case 1:
						MobclickAgent.onEvent(App.getContext(), "v6_1_3_WD_wdwd_pl");
						break;
					case 2:
						MobclickAgent.onEvent(App.getContext(), "v6_1_3_WD_wdwd_dz");
						break;
				}

			}

			@Override
			public void onPageScrollStateChanged(int state) {

			}
		});


	}

	private void initData() {

		for (int i = 0; i <strings.length; i++) {
			fragmentList.add(MyQuestionListFragment.newInstance(params[i]));
		}
		setTabsValue();
		mAdapter.notifyDataSetChanged();
	}









	private void setTabsValue() {
		DisplayMetrics dm = getResources().getDisplayMetrics();
		// 设置Tab底部选中的指示器Indicator的高度
		tabs.setIndicatorHeight(TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 4f, dm));
		// 设置Tab底部选中的指示器 Indicator的颜色
		tabs.setIndicatorColorResource(R.color.green_lab);
		//设置指示器Indicatorin是否跟文本一样宽，默认false
		tabs.setIndicatorinFollowerTv(false);
		//设置小红点提示，item从0开始计算，true为显示，false为隐藏
		//        tabs.setMsgToast(2, true);
		//设置红点滑动到当前页面自动消失,默认为true
		tabs.setMsgToastPager(true);
		//设置Tab标题文字的颜色
		tabs.setTextColor(getResources().getColor(R.color.black));
		// 设置Tab标题文字的大小
		tabs.setTextSize((int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, 14, dm));
		// 设置选中的Tab文字的颜色
		tabs.setSelectedTextColorResource(R.color.green_lab);
		//设置Tab底部分割线的高度
		tabs.setUnderlineHeight(TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 0.5f, dm));
		//设置Tab底部分割线的颜色
		tabs.setUnderlineColorResource(R.color.line_eb);
		// 设置点击某个Tab时的背景色,设置为0时取消背景色tabs.setTabBackground(0);
		//        tabs.setTabBackground(R.drawable.bg_tab);
		tabs.setTabBackground(0);
		// 设置Tab是自动填充满屏幕的
		tabs.setShouldExpand(true);

	}


	public class MyFragmentPagerAdapter extends FragmentPagerAdapter {
		public MyFragmentPagerAdapter(FragmentManager fm) {
			super(fm);
		}

		@Override
		public int getCount() {
			return fragmentList.size();
		}

		@Override
		public Fragment getItem(int arg0) {
			return fragmentList.get(arg0);
		}

		@Override
		public CharSequence getPageTitle(int position) {
			return strings[position];
		}
	}


}
